<?php
/**
 * Created by PhpStorm.
 * User: CCA
 * Date: 2019/10/10
 * Time: 16:01
 */

namespace app\api\controller;


use app\api\BaseController;
use app\common\model\Inviter;
use app\common\model\Search;
use app\common\model\Storeplate;
use app\common\model\Transport;
use app\service\GoodsService;
use app\common\model\Goodproject;
use app\common\model\Goodsclass;
use app\common\model\Brand;
use app\common\model\Favorites;
use think\Request;

/**
 * @title 收藏
 * @description 收藏相关
 */
class Favorite extends BaseController
{
    private $_model_search;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->_model_search = new Favorites();
    }
    
     /**
     * @title 收藏列表
     * @description
     * @author zjw
     * @url /Favorite/select/
     * @method POST
     *
     * @code 200 成功
     * @code 201 失败
     *
     * @param string type 不传查全部1好评2中评3差评
     * @param array goods 商品列表数组格式goods[goodsid][score]/goods[goodsid][comment] ''
     * @return {"code":200,"msg":"succeess"}
     */
    public function select(){
        $member_id = $this->user_id;
        $fav_type = intval(input('post.fav_type'));

        if(empty($fav_type)){
            return json_fail_return('参数错误');
        }
        //页数
        $page = empty(intval(input('param.page'))) ? 20  : intval(input('param.page'));

        $FavoritesModel = new Favorites();
        $comment_list = $FavoritesModel->getFavoriteList($member_id, $fav_type, 20);

        //转换格式  商品
        if($fav_type == 1){
            foreach ($comment_list as $key => $value) {
               $comment_list[$key]['goods_image'] = 'http://33wang.douyinhot.com/' . $value['goods_image'];
               $comment_list[$key]['fav_time'] = date('Y-m-d H:i:s',$value['fav_time']);
            }
        }else{
            foreach ($comment_list as $key => $value) {
               $comment_list[$key]['project_images'] = 'http://33wang.douyinhot.com/' . $value['project_images'];
               $comment_list[$key]['fav_time'] = date('Y-m-d H:i:s',$value['fav_time']);
               $comment_list[$key]['create_time'] = date('Y-m-d',$value['create_time']);
            }
        }
        $result['comment_list'] = $comment_list;
        json_success_return($result);

    }
    /**
     * @title 商品收藏/取消收藏
     * @description
     * @author zjw
     * @url /Favorites/goods_collection       favorites
     * @method GET
     *
     * @code 200 成功
     * @code 201 失败
     *
     * @param string goods_id 商品id null true
     * @return {"code":200,"msg":"succeess"}
     * */

    public function goods_collection() {
        $member_id = $this->user_id;
        $goods_id = input('post.goods_id');
        $fav_type = input('post.fav_type');
        if (empty($goods_id) || empty($fav_type)) {
            return json_fail_return('参数错误');
        }
        $FavoritesModel = new Favorites();
        $result = $FavoritesModel->getGoodsCollection($member_id,$goods_id,$this->user_info,$fav_type);
        return json_success_return($result);
    }



    /**
     * @title 项目定制收藏/取消收藏
     * @description
     * @author zjw
     * @url /Favorites/project_collection
     * @method GET
     *
     * @code 200 成功
     * @code 201 失败
     *
     * @param string goods_id 商品id null true
     * @return {"code":200,"msg":"succeess"}
     * */

    public function project_collection() {
        $member_id = $this->user_id;
        $project_id = input('post.project_id');
        $fav_type = input('post.fav_type');
        if (empty($project_id) || empty($fav_type)) {
            return json_fail_return('参数错误');
        }
        $FavoritesModel = new Favorites();
        $result = $FavoritesModel->getProjectCollection($member_id,$project_id,$this->user_info,$fav_type);
        return json_success_return($result);
    }


    

}